<?php
/**
 * Created by PhpStorm.
 * User: 86158
 * Date: 2021/6/15
 * Time: 23:09
 */

namespace App\Models\access;


use App\Models\Model;
use App\Models\User;

class AccessVoteMember extends Model
{
    protected $fillable = [
        'user_id',
        'score',
        'access_id',
        'remark'
    ];

    public function access()
    {
        return $this->hasOne(AccessVote::class,'id','access_id');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }

    public function accessLog()
    {
        return $this->hasMany(AccessVoteLog::class,'user_id','user_id');
    }

//    public function leader()
//    {
//        return $this->hasMany(AccessVoteLeader::class,'access_id','access_id');
//    }

    public function lists($user_id)
    {
        $map[] = ['user_id','=',$user_id];
        return self::where($map)->with('access')->select(['access_id','score'])->get()->toArray();
    }

    public function detail($user_id,$access_id)
    {
        $map = [
            'access_id' => $access_id,
            'user_id'   => $user_id
        ];
        return self::where($map)->with('user')->with('access')->select(['score'])->first();
    }
}